#include "TeaMaker.h"

// Qt Includes
#include <QTcpSocket>

// Local Includes
#include "TeaMakerTrayIcon.h"
#include "TeaMakerServerSocket.h"
#include "tmthreadmanager.h"
#include "tmsvrsettingsdlg.h"

// ------------------------------------------------------------
// Construction & Destruction
// ------------------------------------------------------------
CTeaMaker::CTeaMaker(QObject *const parent/* = NULL*/)
	: QObject(parent)
{
	m_pTrayIcon = new CTeaMakerTrayIcon(this);
	m_pTcpServer = new CTeaMakerServerSocket(this);
	m_pThreadManager = new CTMThreadManager(this);

	m_pTrayIcon->show();

	connect(m_pTrayIcon, SIGNAL(configureServer()), this, SLOT(showConfigUI()));
	connect(m_pTcpServer, SIGNAL(newConnection(int)), m_pThreadManager, SLOT(newConnection(int)));
}

CTeaMaker::~CTeaMaker()
{
	
}

// ------------------------------------------------------------
// Member Functions
// ------------------------------------------------------------
bool CTeaMaker::listen(const QHostAddress &address/* = QHostAddress::Any*/, quint16 port/* = 0*/)
{
	return m_pTcpServer->listen(address, port);
}

void CTeaMaker::showConfigUI()
{
	CTmSvrSettingsDlg dlg;
	dlg.exec();
}
